<?php
// 文件名 api/controller/News.php
namespace app\api\controller;

use app\common\controller\Api;


/**
 * 资讯接口
 */
class News extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /** 
     * 资讯列表
     *
     */
    public function index()
    {
        // $category = input('param.category')?input('param.category'):'all';
        // $per_page = input('param.per_page')?input('param.per_page'):6;
        // $map = [];
        // if($category != 'all'){
        //     $map['category_id'] =['NEQ','13'];
        // }else{
        //     $map['category_id'] = $category;
        // }
        // if($category != 'all'){
        //     $map['category_id'] =$category;
        // }
        // $data = model('News')
        //     ->where($map)
        //     ->field('content',true) // 过滤content字段
        //     ->order('createtime desc') // 排序字段
        //     ->paginate($per_page);

        // $this->success('查询成功！', $data);    

 /** 
     * 资讯列表
     *
     */
 
        $category = input('param.category')?input('param.category'):'all';
        $per_page = input('param.per_page')?input('param.per_page'):6;
        $map = [];
        if($category == 'all'){
            $map['category_id'] = ['NEQ','12']; // 排除通知公告分类
        }else{
            $map['category_id'] = $category;
        }
       
        $data = model('News')
            ->where($map)
            ->field('content',true) // 过滤content字段
            ->order('createtime desc') // 排序字段
            ->paginate($per_page);

        $this->success('查询成功！', $data);    
    

    }

    // 资讯详情
    public function detail(){
        if(!input('?param.id')){
            $this->error('参数不正确！');   
        }
        $data = model('News')
            ->where('id',input('id'))
            ->find();

        $this->success('查询成功！', $data);    
    }
}
